﻿using System;
using System.Text;
using System.Collections.Generic;
using Demo_G.O.S.E.ServerEngine.Util;
using Demo_G.O.S.E.ServerEngine.Creature;
using Demo_G.O.S.E.ServerEngine.Common;
using Demo_G.O.S.E.ServerEngine.Network;

namespace Demo_G.O.S.E.ServerEngine.Skill
{
    /// <summary>
    /// 
    /// </summary>
    public class Skills
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="owner"></param>
        public Skills( BaseCreature owner )
        {
            m_Owner = owner;

            SkillInfo[] info = SkillInfo.Table;

            m_Skills = new BaseSkill[info.Length];

            //for ( int i = 0; i < info.Length; ++i )
            //	m_Skills[i] = new BaseSkill( this, info[i], 0, 1000, SkillLock.Up );
        }

        /// <summary>
        /// 
        /// </summary>
        private int m_Total = 0;
        /// <summary>
        /// 
        /// </summary>
        public int Total
        {
            get { return m_Total; }
        }

        private BaseCreature m_Owner;
        public BaseCreature Owner
        {
            get { return m_Owner; }
        }

        private BaseSkill[] m_Skills;
        public BaseSkill this[int skillID]
        {
            get
            {
                if ( skillID < 0 || skillID >= m_Skills.Length )
                    return null;

                BaseSkill sk = m_Skills[skillID];

                if ( sk == null )
                    m_Skills[skillID] = sk = new BaseSkill( this, SkillInfo.Table[skillID], 0, 1000, SkillLock.Up );

                return sk;
            }
        }

        public static bool UseSkill( BaseCreature from, SkillName name )
        {
            return UseSkill( from, (int)name );
        }

        public static bool UseSkill( BaseCreature from, int skillID )
        {
            //if ( !from.CheckAlive() )
            //    return false;
            //else if ( !from.Region.OnSkillUse( from, skillID ) )
            //    return false;
            //else if ( !from.AllowSkillUse( (SkillName)skillID ) )
            //    return false;

            //if ( skillID >= 0 && skillID < SkillInfo.Table.Length )
            //{
            //    SkillInfo info = SkillInfo.Table[skillID];

            //    if ( info.Callback != null )
            //    {
            //        if ( from.NextSkillTime <= DateTime.Now && from.Spell == null )
            //        {
            //            from.DisruptiveAction();

            //            from.NextSkillTime = DateTime.Now + info.Callback( from );

            //            return true;
            //        }
            //        else
            //        {
            //            from.SendSkillMessage();
            //        }
            //    }
            //    else
            //    {
            //    }
            //}

            return false;
        }


        public void OnSkillChange( BaseSkill skill )
        {
            //if ( skill == m_Highest ) // could be downgrading the skill, force a recalc
            //    m_Highest = null;
            //else if ( m_Highest != null && skill.BaseFixedPoint > m_Highest.BaseFixedPoint )
            //    m_Highest = skill;

            //m_Owner.OnSkillInvalidated( skill );

            //NetState ns = m_Owner.NetState;

            //if ( ns != null )
            //    ns.Send( new SkillChange( skill ) );
        }

        public override string ToString()
        {
            return "...";
        }

    }
}

